// pages/member/presentationDetails/presentationDetails.js
var app = getApp();
Page({

  /**
	 * 页面的初始数据
	 */
  data: {
    language: '',
    record_id: '',
    //打款金额
    actual_amounts: 0,
    //打款手续费
    actual_poundage: 0,
    //类型
    type_name: '',
    withdraw_sn: '',
    created_at: '',
    poundage_name:'',
    actual_servicetax:0,
    pay_way_name:"",
    name_of_withdrawal:"",
    //备注
    reject_reason:'',

    amount_show:false,
    amount_detail:{
      data:[],
      current_page:1,
      last_page:1,
      isLoadMore:true
    },
  },

  /**
	 * 生命周期函数--监听页面加载
	 */
  onLoad: function(options) {
    if (options.record_id) {
      this.setData({
        record_id: options.record_id
      });
    }
    this._getData();
    this.customizeIncome();
    wx.createIntersectionObserver().relativeToViewport({bottom: 1}).observe('.amount-popup-details', (res) => {
      console.log(res)
      res.intersectionRatio // 相交区域占目标节点的布局区域的比例
      res.intersectionRect // 相交区域
      res.intersectionRect.left // 相交区域的左边界坐标
      res.intersectionRect.top // 相交区域的上边界坐标
      res.intersectionRect.width // 相交区域的宽度
      res.intersectionRect.height // 相交区域的高度
    })
  },
  onClose(){
    this.setData({amount_show:false})
  },
  amount_dialog(){
    this.setData({amount_show:true})
    let urlStr = app.getNetAddresss("finance.withdraw.incomelist");
    urlStr += '&id=' + this.data.record_id;
     app._getNetWork({
       url:urlStr,
       success:resdata=>{
         if(resdata.data.result==0){
           return app.tips(resdata.data.msg);
         }
         let {data,current_page,last_page} = resdata.data.data;
         this.setData({
          "amount_detail.data":data,
          "amount_detail.current_page":current_page,
          "amount_detail.last_page":last_page
         })
       }
    })

  },
  lower(){
    if(this.data.amount_detail.current_page>=this.data.amount_detail.last_page){
      return;
    }
    if(this.data.amount_detail.isLoadMore){
      let page = this.data.amount_detail.current_page+1;
      let urlStr = app.getNetAddresss("finance.withdraw.incomelist");
      urlStr += '&id=' + this.data.record_id + '&page='+page;
       app._getNetWork({
         url:urlStr,
         success:resdata=>{
           this.setData({'amount_detail.isLoadMore':true})
           if(resdata.data.result==0){
             return app.tips(resdata.data.msg);
           }
           let {data,current_page,last_page} = resdata.data.data;
           this.setData({
            "amount_detail.data":this.data.amount_detail.data.concat(data),
            "amount_detail.current_page":current_page,
            "amount_detail.last_page":last_page
           })
         }
      })
    }
  },
  //自定义提现收入语言
  customizeIncome() {
    try {
      var value = wx.getStorageSync('mailLanguage');
      if (value) {
        let mailLanguage = JSON.parse(value);
        // Do something with return value
        this.setData({
          poundage_name: mailLanguage.income.poundage_name,
          name_of_withdrawal:mailLanguage.income.name_of_withdrawal
        });
      }
    } catch (e) {
      // Do something when catch error
    }
  },
  /**
	 * 生命周期函数--监听页面初次渲染完成
	 */
  onReady: function() {
    let language = wx.getStorageSync('langIndex');
    this.setData({ 'language': language.en});
  },

  /**
	 * 生命周期函数--监听页面显示
	 */
  onShow: function() {

  },

  /**
	 * 生命周期函数--监听页面隐藏
	 */
  onHide: function() {

  },

  /**
	 * 生命周期函数--监听页面卸载
	 */
  onUnload: function() {

  },

  /**
	 * 页面相关事件处理函数--监听用户下拉动作
	 */
  onPullDownRefresh: function() {

  },

  /**
	 * 页面上拉触底事件的处理函数
	 */
  onReachBottom: function() {

  },

  /**
	 * 用户点击右上角分享
	 */
  onShareAppMessage: function() {

  },
  //获取数据
  _getData() {
    let that = this;
    let urlStr = app.getNetAddresss("finance.withdraw.withdraw-info");
    urlStr += '&id=' + this.data.record_id;
    app._getNetWork({
      url: urlStr,
      success: function(resdata) {
        var res = resdata.data;
        if (res.result == 1) {
          var mydata = res.data;
          that.setData({
            pay_way_name:mydata.pay_way_name,
            actual_poundage: mydata.actual_poundage,
            amounts: mydata.amounts,
            type_name: mydata.type_name,
            withdraw_sn: mydata.withdraw_sn,
            created_at: mydata.created_at,
            actual_amounts: mydata.actual_amounts,
            actual_servicetax:mydata.actual_servicetax || '0.00',
            reject_reason:mydata.reject_reason || '',
          });
        } else {
          wx.showToast({
            icon: 'none',
            title: res.msg,
            duration: 1500
          });
        }
      },
      fail: function(res) {
        console.log(res);
      }
    });
  },
});
